package com.huitone.smspfm.oldclient.model;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import com.bin.common.utils.StringUtils;
import com.huitone.smspfm.oldclient.app.AppStaticConfigs;
import com.huitone.smspfm.oldclient.logger.ExtLogger;

/**   
* @Title: DeliverSms.java 
* @Package com.unicom.gddw.dao.entity 
* @Description: 上行短信 
* @author ybliang   
* @date 2017年3月17日 上午11:09:26 
* @version V1.0   
*/
public class RecvSms extends AbstractSms {

	private static final long serialVersionUID = 1L;
	
	private final static ExtLogger logger = ExtLogger.create(RecvSms.class);
	
	// "<serialno>"+serialno+"</serialno><clientname>"+clientname+"</clientname><sendport>"+sendport+"</sendport>
	// <mobileno>"+mobileno+"</mobileno><content>"+content+"</content><crttime>"+crttime+"</crttime><endl/>\n";
	
	public static Map<String,String> DELIVER_ELEMENTS = new HashMap<String,String>() {

		private static final long serialVersionUID = 1L;
		
		{
			put("serialno","<serialno>?</serialno>");
			put("clientname","<clientname>?</clientname>");
			put("sendport","<sendport>?</sendport>");
			put("mobileno","<mobileno>?</mobileno>");
			put("content","<content>?</content>");
			put("crttime","<crttime>?</crttime>");
			put("endl", "<endl/>");
		}
		
	};
	
	public static Map<String,String> DELIVER_ELEMENTS_METHODS = new HashMap<String,String>() {

		private static final long serialVersionUID = 1L;
		
		{
			put("serialno","getSerialno");
			put("clientname","getClientname");
			put("sendport","getSendport");
			put("mobileno","getMobileno");
			put("content","getContent");
			put("crttime","getCrttime");
			
		}
		
	};
	
	private String content;
	private String crttime;
	
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public String getCrttime() {
		return crttime;
	}
	public void setCrttime(String crttime) {
		this.crttime = crttime;
	}
	
	@Override
	public String toString() {
		
		StringBuffer buffer = new StringBuffer();
		
		for (String element:AppStaticConfigs.dlvRowElements) {
			
			try {
				
				if (StringUtils.equals("endl", element)) {
					buffer.append(DELIVER_ELEMENTS.get(element));
				} else {
					String name = DELIVER_ELEMENTS_METHODS.get(element);
					if (!StringUtils.isEmpty(name)) {
						Method method = this.getClass().getMethod(name, new Class[]{});
						try {
							buffer.append(StringUtils.replace(DELIVER_ELEMENTS.get(element), "?", StringUtils.toString(method.invoke(this, new Object[]{}))));
						} catch (IllegalAccessException e) {
							e.printStackTrace();
						} catch (IllegalArgumentException e) {
							e.printStackTrace();
						} catch (InvocationTargetException e) {
							e.printStackTrace();
						}
					}
				}
			} catch (NoSuchMethodException e) {
				logger.error("不存在的上行短信文件元素:" + element, e);
			} catch (SecurityException e) {
				e.printStackTrace();
			}
		}
		
		return buffer.toString();
	}
	
}
